package 二分查找;

public class LeetCode209_长度最小的子数组 {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int right = left;
        int count = 0;
        int sum = 0;
        while(right < nums.length) {
            sum += nums[right];
            //这里要用 while 不能用 if
            while(sum >= target) {
                if(count == 0) {
                    count = right - left + 1;
                    sum -= nums[left++];
                } else {
                    count = Math.min(count, (right-left+1));
                    sum -= nums[left++];
                }
            }
            right++;
        }
        return count;
    }
}
